package com.etc.delivery.service.admin.impl;

import com.etc.delivery.dao.admin.AdminWarehouseDao;
import com.etc.delivery.entity.Warehouse;
import com.etc.delivery.service.admin.IAdminWarehouseService;
import com.etc.delivery.utils.MD5Utils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AdminWarehouseServiceImpl implements IAdminWarehouseService {

    @Resource
    private AdminWarehouseDao warehouseDao;

    @Override
    public PageInfo<Warehouse> queryWarehouse(String name, String address, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Warehouse> list = warehouseDao.queryWarehouse(name, address);
        PageInfo pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<Warehouse> queryWarehouseName() {
        return warehouseDao.queryWarehouseName();
    }

    @Override
    public List<Warehouse> queryDeletedWarehouse(String name, String address) {
        return warehouseDao.queryDeletedWarehouse(name, address);
    }

    @Override
    public boolean addWarehouse(Warehouse warehouse) {
        warehouse.setPassword(MD5Utils.getPWD(warehouse.getPassword()));
        return warehouseDao.addWarehouse(warehouse);
    }

    @Override
    public boolean deleteWarehouse(Integer id) {
        return warehouseDao.deleteWarehouse(id);
    }

    @Override
    public boolean resumeWarehouse(Integer id) {
        return warehouseDao.resumeWarehouse(id);
    }

    @Override
    public boolean writeOff(Integer id) {
        return warehouseDao.writeOff(id);
    }

    @Override
    public boolean updateWarehouse(Warehouse warehouse) {
        return warehouseDao.updateWarehouse(warehouse);
    }

    @Override
    public List<Warehouse> queryWarehousePhone(String phone) {
        List<Warehouse> list = warehouseDao.queryWarehousePhone(phone);

        return list;
    }
}
